import time

from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.remote.webdriver import WebDriver

from page.login_page import LoginPage
from page.search_page import SearchPage


class MainPage:
    def __init__(self, driver: WebDriver):
        self.driver = driver
    def to_search_page(self):
        el3 = self.driver.find_element_by_id("com.xqxc.customer:id/iv_search")
        el3.click()
        return SearchPage(self.driver)

    def to_login(self):
        el2 = self.driver.find_element_by_id("com.xqxc.customer:id/tabMeIv")
        el2.click()
        return LoginPage(self.driver)
    def to_swipe_up(self):
        TouchAction(self.driver).press(x=545, y=1868).move_to(x=623, y=587).release().perform()
        time.sleep(1)
        # TouchAction(self.driver).press(x=545, y=1868).move_to(x=623, y=587).release().perform()
    def to_swipe_down(self):
        TouchAction(self.driver).press(x=623, y=587).move_to(x=545, y=1868).release().perform()
        time.sleep(1)
        # TouchAction(self.driver).press(x=623, y=587).move_to(x=545, y=1868).release().perform()

    def to_swipe_left(self):
        TouchAction(self.driver).press(x=948, y=1188).move_to(x=90, y=1176).release().perform()
        time.sleep(1)

    def to_swipe_right(self):
        TouchAction(self.driver).press(x=90, y=1176).move_to(x=948, y=1188).release().perform()
        time.sleep(1)